package ua.com.fesvlast.hotel.model.commands;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import ua.com.fesvlast.hotel.controller.managers.ConfigurationManager;
import ua.com.fesvlast.hotel.controller.managers.MessageManager;
import ua.com.fesvlast.hotel.model.dao.DAOFactory;
import ua.com.fesvlast.hotel.model.enteties.HotelRooms;


public class ForwardOrder implements ICommand{
	
	
	@Override
	public String execute(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		 
		String page =null;
		 int id =Integer.valueOf(request.getParameter("room_id"));
		 HotelRooms room =DAOFactory.getHotelsRoomsDAO().getChosenRoom(id);
		 
		
		 
		 if(room!=null){
			request.setAttribute("room", room);
				page=ConfigurationManager.getInstance().getProperty(ConfigurationManager.FORWARD_ORDER_PAGE);
			}else{
				request.setAttribute("errorMessage", MessageManager.getInstance().getProperty(
						MessageManager.LOGIN_ERROR_MESSAGE));
				
				page=ConfigurationManager.getInstance().getProperty(
						ConfigurationManager.ERROR_PAGE_PATH);
			}
		 
		 if(request.getSession().getAttribute("currentUser")==null){
			 page=ConfigurationManager.getInstance().getProperty(ConfigurationManager.LOGIN_PAGE_PATH);
		 }
		
		return page;
	}

}
